import unittest
import time

from selenium.webdriver.common.by import By

from common.base import get_driver
from page.shopping_page import ShoppingPage


class Shoppping_Add_TestCase(unittest.TestCase):
    def test_shopping_add(self):
        # TODO 操作流程
        # 创建driver
        driver = get_driver()
        driver.get("http://localhost:8080/ecshop/flow.php")
        driver.maximize_window()
        # 创建页面对象
        self.shopping = ShoppingPage(driver)
        self.shopping.add_goods()
        time.sleep(1)

        # TODO 断言
        """
        预期 和 实际结果 的比对
        """
        goods_name = self.shopping.get_text((By.XPATH, "//div[@class='goods_style_name']"))
        actual_goods_name = self.shopping.get_text((By.LINK_TEXT, "随身风扇"))
        self.assertEqual(goods_name, actual_goods_name, msg="商品添加失败")


if __name__ == '__main__':
    unittest.main(verbosity=2)
